9 int deltaCol
[] = {-2, -1, 1, 2, 2, 1, -1, -2};
10 int deltaFil
[] = {-1, -2, -2, -1, 1, 2, 2, 1};
12 int rdeltaCol
[] = { -1, 0, 1, 1, 1, 0, -1, -1};
13 int rdeltaFil
[] = { -1, -1, -1, 0, 1, 1, 1, 0};
15 int inicialCol
, inicialFil
;
18 unsigned int d
[101][101];
20 int m
, n
; //m filas, n columnas
27 memset(color
, WHITE
, sizeof(color
));
28 //memset(d, 2147483647, sizeof(d));
30 for (int i
=0; i
<=100; ++i
) for (int j
=0; j
<=100; ++j
) d
[i
][j
] = UINT_MAX
;
32 color
[inicialFil
][inicialCol
] = GRAY
;
33 d
[inicialFil
][inicialCol
] = 0;
35 queue
< pair
<int,int> > q
;
36 q
.push(make_pair(inicialFil
, inicialCol
));
38 //printf("Empezando en: (%d,%d)\n", inicialFil, inicialCol);
41 int fil
= q
.front().first
, col
= q
.front().second
;
43 //printf("Saque el nodo (%d,%d) de la cola.\n", fil, col);
45 if (g
[fil
][col
] == 'B'){
46 cout
<< "Minimal possible length of a trip is ";
47 cout
<< d
[fil
][col
] << endl
;
51 for (int k
=0; k
<8; ++k
){
53 tempFil
= fil
+ rdeltaFil
[k
];
54 tempCol
= col
+ rdeltaCol
[k
];
55 //if (tempFil >= 0 && tempFil < m && tempCol >= 0 && tempCol < n){
56 if ( (tempFil
>= 0) && (tempFil
< m
) && (tempCol
>= 0) && (tempCol
< n
)){
57 char c
= g
[tempFil
][tempCol
];
59 //printf("Considerando para marcado el nodo(%d,%d) que contiene %c\n", tempFil, tempCol, c);
61 if (c
!= 'Z' && c
!= 'X'){
63 //printf("Nodo visitable (%d,%d), revisando que sea blanco.\n", tempFil, tempCol);
65 if (color
[tempFil
][tempCol
] == WHITE
){
66 color
[tempFil
][tempCol
] = GRAY
;
68 //printf("Marcando gris el nodo (%d,%d)\n", tempFil, tempCol);
70 d
[tempFil
][tempCol
] = d
[fil
][col
] + 1;
71 q
.push(make_pair(tempFil
, tempCol
));
77 color
[fil
][col
] = BLACK
;
79 printf("King Peter, you can't go now!\n");
88 for (int i
=0; i
<m
; ++i
){
89 for (int j
=0; j
<n
; ++j
){
102 for (int i
=0; i
<m
; ++i
){
103 for (int j
=0; j
<n
; ++j
){
105 for (int k
=0; k
<8; ++k
){
106 int tempFil
, tempCol
;
107 tempFil
= i
+ deltaFil
[k
];
108 tempCol
= j
+ deltaCol
[k
];
109 if (tempFil
>= 0 && tempFil
<= m
&& tempCol
>=0 && tempCol
< n
){
110 char c
= g
[tempFil
][tempCol
];
111 if (c
!= 'B' && c
!= 'A' && c
!= 'Z') g
[tempFil
][tempCol
] = 'X';
118 //En este momento, g[i][j] contiene una X si es una casilla atacable
123 /*for (int i=0; i<m; ++i){
124 for (int j=0; j<n; ++j){